<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绘制八卦图</title>
    <style>
        canvas{
            border: 1px solid #333;
            background: #f4f4f4;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="600" height="600"></canvas>
    <script>
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');

        // 将坐标原点移动至画布中心
        ctx.translate(300,300);

        ctx.beginPath();
        ctx.arc(0,0,200,1.5 * Math.PI,0.5 * Math.PI,false);
        ctx.fillStyle = "#fff";
        ctx.fill();

        ctx.beginPath();
        ctx.arc(0,0,200,0.5 * Math.PI, Math.PI * 1.5,false);
        ctx.fillStyle = '#000';
        ctx.fill();

        ctx.beginPath();
        ctx.arc(0,-100,100, 0, Math.PI * 2, false);
        ctx.fillStyle = '#fff';
        ctx.fill();

        ctx.beginPath();
        ctx.arc(0,-100,30, 0, Math.PI * 2, false);
        ctx.fillStyle = '#000';
        ctx.fill();

        ctx.beginPath();
        ctx.arc(0,100,100, 0, Math.PI * 2, false);
        ctx.fillStyle = '#000';
        ctx.fill();

        ctx.beginPath();
        ctx.arc(0,100,30, 0, Math.PI * 2, false);
        ctx.fillStyle = '#fff';
        ctx.fill();
   
    </script>
</body>
</html>